# -*- coding: utf-8 -*-
#
# File: Encomenda.py
#
# Copyright (c) 2006 by IBICT
# Generator: ArchGenXML Version 1.5.0
#            http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

__author__ = """IBICT <cadu@ibict.br>"""
__docformat__ = 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from Products.SIGFS.content.Instrumento import Instrumento
from Products.Archetypes.SQLStorage import *
from Products.SIGFS.config import *

##code-section module-header #fill in your manual code here
from Products.Archetypes import transaction
##/code-section module-header

schema = Schema((

),
)

##code-section after-local-schema #fill in your manual code here
##/code-section after-local-schema

Encomenda_schema = BaseBTreeFolderSchema.copy() + \
    getattr(Instrumento, 'schema', Schema(())).copy() + \
    schema.copy()

##code-section after-schema #fill in your manual code here
##/code-section after-schema

class Encomenda(Instrumento, BaseBTreeFolder):
    """
    """
    security = ClassSecurityInfo()
    __implements__ = (getattr(Instrumento,'__implements__',()),) + (getattr(BaseBTreeFolder,'__implements__',()),)

    # This name appears in the 'add' box
    archetype_name = 'Encomenda'

    meta_type = 'Encomenda'
    portal_type = 'Encomenda'
    allowed_content_types = ['Files'] + list(getattr(Instrumento, 'allowed_content_types', []))
    filter_content_types = 1
    global_allow = 0
    content_icon = 'shopping_cart.gif'
    immediate_view = 'base_view'
    default_view = 'encomenda_view'
    suppl_views = ()
    typeDescription = "Encomenda gerada pelo Termo de Referência. É adicionada ao Escritório Virtual pelas Agências. Referencia o projeto. Para adicionar um arquivo referente ao Instrumento, clicar no link 'Adicionar novo item' e escolher 'Arquivo'."
    typeDescMsgId = 'description_edit_encomenda'


    actions =  (


       {'action': "string:${object_url}/encomenda_view",
        'category': "object",
        'id': 'view',
        'name': 'View',
        'permissions': ("View",),
        'condition': 'python:1'
       },


       {'action': 'string:${object_url}/folder_localrole_form',
        'category': "object",
        'id': 'sharing',
        'name': 'Sharing',
        'permissions': ("SIGFS: Add Encomenda",),
        'condition': 'python:1'
       },


    )

    _at_rename_after_creation = True

    schema = Encomenda_schema

    ##code-section class-header #fill in your manual code here
    ##/code-section class-header

    # Methods

    # Manually created methods

    security.declarePrivate('_renameAfterCreation')
    def _renameAfterCreation(self, check_auto_id=False):
        """Renomeia o objeto com id numérico sequencial de 6 casas decimais."""
	parent_ids = self.aq_inner.aq_parent.objectIds()
        try:
          new_id = 'en'+'%0.4i' % len(parent_ids)
          # Usando o portal_factory tem que comitar a subtransacao
          transaction.savepoint(optimistic=True)
	  self.setId(new_id)
	except:
	  new_id = 'en'+'%0.4i' % len(parent_ids) + str(random.randint(1,1000))
          # Usando o portal_factory tem que comitar a subtransacao
          transaction.savepoint(optimistic=True)
	  self.setId(new_id)



registerType(Encomenda, PROJECTNAME)
# end of class Encomenda

##code-section module-footer #fill in your manual code here
##/code-section module-footer



